package com.apanal.qlife.sys.model;

import java.util.List;

import com.apanal.qlife.common.model.BaseModel;

/**
 * 资源实体类
 * 
 * 
 * @author shuliangxing
 * 
 * @date 2015-8-31下午5:42:20
 */
public class Resource extends BaseModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3845403203118737471L;

	/**
	 * id
	 */
	private Long resId;

	/**
	 * 资源名称
	 */
	private String resName;

	/**
	 * 资源类型, 1:菜单,2:按钮
	 */
	private Integer resType;

	/**
	 * 资源url
	 */
	private String resUrl;

	/**
	 * 显示顺序
	 */
	private Integer resOrder;

	/**
	 * 资源样式,html class样式名称
	 */
	private String resClass;

	/**
	 * 资源层级
	 */
	private Integer resLevel;

	/**
	 * 父id
	 */
	private Long resPId;

	/**
	 * 父编号列表,斜线"/"分隔
	 */
	private String resPIds;

	/**
	 * 权限字符串
	 */
	private String resPermission;

	/**
	 * 数据是否正常(可逆状态), 1:正常, 0:停用,来自t_dictionary.NORMAL
	 */
	private Integer normal;

	/**
	 * 子资源集合
	 */
	private List<Resource> childResList;

	public Long getResId() {
		return resId;
	}

	public void setResId(Long resId) {
		this.resId = resId;
	}

	public String getResName() {
		return resName;
	}

	public void setResName(String resName) {
		this.resName = resName == null ? null : resName.trim();
	}

	public Integer getResType() {
		return resType;
	}

	public void setResType(Integer resType) {
		this.resType = resType;
	}

	public Integer getResOrder() {
		return resOrder;
	}

	public void setResOrder(Integer resOrder) {
		this.resOrder = resOrder;
	}

	public Long getResPId() {
		return resPId;
	}

	public void setResPId(Long resPId) {
		this.resPId = resPId;
	}

	public String getResPIds() {
		return resPIds;
	}

	public void setResPIds(String resPIds) {
		this.resPIds = resPIds == null ? null : resPIds.trim();
	}

	public String getResPermission() {
		return resPermission;
	}

	public void setResPermission(String resPermission) {
		this.resPermission = resPermission == null ? null : resPermission
				.trim();
	}

	public Integer getNormal() {
		return normal;
	}

	public void setNormal(Integer normal) {
		this.normal = normal;
	}

	public String getResUrl() {
		return resUrl;
	}

	public void setResUrl(String resUrl) {
		this.resUrl = resUrl;
	}

	public Integer getResLevel() {
		if (resLevel == null && resPIds != null) {
			return resPIds.split("/").length;
		} else {
			return resLevel;
		}
	}

	public void setResLevel(Integer resLevel) {
		this.resLevel = resLevel;
	}

	public List<Resource> getChildResList() {
		return childResList;
	}

	public void setChildResList(List<Resource> childResList) {
		this.childResList = childResList;
	}

	// 分割线

	/**
	 * 返回把当前资源当做父资源时的父资源id字符串
	 * 
	 * @return
	 */
	public String makeSelfAsParentIds() {
		return getResPIds() + getResId() + "/";
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Resource resource = (Resource) o;

		if (resId != null ? !resId.equals(resource.resId)
				: resource.resId != null)
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		return resId != null ? resId.hashCode() : 0;
	}

	public String getResClass() {
		return resClass;
	}

	public void setResClass(String resClass) {
		this.resClass = resClass;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "Resource [resId=" + resId + ", resName=" + resName
				+ ", resType=" + resType + ", resUrl=" + resUrl + ", resOrder="
				+ resOrder + ", resClass=" + resClass + ", resLevel="
				+ resLevel + ", resPId=" + resPId + ", resPIds=" + resPIds
				+ ", resPermission=" + resPermission + ", normal=" + normal
				+ ", childResList=" + childResList + "]";
	}

}